package com.yuchengtech.test.pack.action;

import java.io.File;

import com.wox.action.JsonData;
import com.wox.action.WoxAction;
import com.yuchengtech.fileUtil.FileIo;

public class FormatListFileAction extends WoxAction {

	String filePath;
	
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}


	@Override
	public String excute() throws Exception {
	
		JsonData data=getJsonData();
		if(filePath!=null)
		{
			File file=new File(filePath);
			if(file.exists()&&file.isFile()&&file.length()!=0)
			{
			String content=FileIo.readFileAsString(file);
			content=doFormat(content);
			FileIo.writeToFile(file,content,null);
			data.setState(true);
			data.setMessage("格式化成功!");
			}else
			{
				data.setMessage("列表文件不存在或为空,或者是文件夹!");
			}
		}
		return JSONBACK;
	}

	private static String[] repSrc={"/cmis-main/src/main/java",".java","/cmis-main/WebContent/WEB-INF/"};
	private static String[] repRes={"classes",".class",""};
	public String doFormat(String content)
	{
		for(int i=0;i<repSrc.length;i++)
		{
			content=content.replaceAll(repSrc[i], repRes[i]);
		}
		return content;
	}
}
